package com.example.webwork.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.webwork.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.RequestParam;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    @Update("INSERT INTO user_1 (id, name,email) VALUES (#{id}, #{name}, #{email})")
    User save(User user);

    // 更新用户密码

    @Select("SELECT * FROM user_1 WHERE id = #{id}")
    User getUserByIdFromDb0_user1(@RequestParam("id") Long id);

    @Select("SELECT * FROM user_2 WHERE id = #{id}")
    User getUserByIdFromDb1_user2(@RequestParam("id") Long id);

    @Update("UPDATE user_1 SET password = #{password} WHERE id = #{id}")
    User updateUserPasswordFromDb0_user1(@RequestParam("id") Long id, @RequestParam("password") String password);

    @Update("UPDATE user_2 SET password = #{password} WHERE id = #{id}")
    User updateUserPasswordFromDb1_user2(@RequestParam("id") Long id, @RequestParam("password") String password);
}
